package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DsTeacher;
import com.ruoyi.system.service.IDsTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师信息Controller
 *
 * @author tyro
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/system/teacher")
public class DsTeacherController extends BaseController
{
    @Autowired
    private IDsTeacherService dsTeacherService;

    /**
     * 查询教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(DsTeacher dsTeacher)
    {
        startPage();
        List<DsTeacher> list = dsTeacherService.selectDsTeacherList(dsTeacher);
        return getDataTable(list);
    }


    /**
     * 查询教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/listTeacherForClass")
    public TableDataInfo listTeacherForClass(DsTeacher dsTeacher)
    {
        startPage();
        List<DsTeacher> list = dsTeacherService.selectDsTeacherListForClass(dsTeacher);
        return getDataTable(list);
    }


    /**
     * 导出教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:export')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DsTeacher dsTeacher)
    {
        List<DsTeacher> list = dsTeacherService.selectDsTeacherList(dsTeacher);
        ExcelUtil<DsTeacher> util = new ExcelUtil<DsTeacher>(DsTeacher.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return success(dsTeacherService.selectDsTeacherByTeacherId(teacherId));
    }


    /**
     * 删除教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:remove')")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(dsTeacherService.deleteDsTeacherByTeacherIds(teacherIds));
    }

    /**
     * 新增教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:add')")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DsTeacher dsTeacher)
    {
        // 添加创建人信息
        dsTeacher.setCreateBy(getUsername());
        // 调用服务方法处理用户同步
        return toAjax(dsTeacherService.insertDsTeacher(dsTeacher));
    }

    /**
     * 修改教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:edit')")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DsTeacher dsTeacher)
    {
        // 添加更新人信息
        dsTeacher.setUpdateBy(getUsername());
        return toAjax(dsTeacherService.updateDsTeacher(dsTeacher));
    }

    /**
     * 重置教师密码
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:edit')")
    @Log(title = "重置教师密码", businessType = BusinessType.UPDATE)
    @PutMapping("/resetPassword/{teacherId}")
    public AjaxResult resetPassword(@PathVariable("teacherId") Long teacherId)
    {
        return toAjax(dsTeacherService.resetTeacherPassword(teacherId));
    }
}
